package com.example.icedcap.topeka_fake.model.quiz;

import android.os.Parcel;

import com.example.icedcap.topeka_fake.helper.AnswerHelper;

import java.util.Arrays;

/**
 * Author: doushuqi
 * Date: 15/7/15
 * Time: 上午11:17
 * Email: shuqi.dou@singuloid.com
 */
public final class FillTwoBlanksQuiz extends Quiz<String[]> {
    public FillTwoBlanksQuiz(String question, String[] answer, boolean solved) {
        super(question, answer, solved);
    }

    protected FillTwoBlanksQuiz(Parcel in) {
        super(in);
        String[] answer = in.createStringArray();
        setAnswer(answer);
    }

    @Override
    public QuizType getQuizType() {
        return QuizType.FILL_TWO_BLANKS;
    }

    @Override
    public String getStringAnswer() {
        return AnswerHelper.getAnswer(getAnswer());
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = result * 31 + Arrays.hashCode(getAnswer());
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof FillTwoBlanksQuiz)) {
            return false;
        }
        FillTwoBlanksQuiz that = (FillTwoBlanksQuiz) o;
        final String[] answer = getAnswer();
        final String question = getQuestion();
        if (null != answer ? !Arrays.equals(answer, that.getAnswer()) : that.getAnswer() != null) {
            return false;
        }
        if (!that.getQuestion().equals(question)) {
            return false;
        }
        return true;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeStringArray(getAnswer());
    }
}
